package cn.yuemouren.leetcode;

/**
 * @Author: Timi
 * @Description: 14.最长公共前缀
 * @Date: 2020/8/18 8:54
 */
public class Test14 {
    public String longestCommonPrefix(String[] strs) {

        String ret = "";

        if(strs.length == 0) return ret;
        if(strs.length == 1) return strs[0];

        ret = strs[0];

        for (int i = 1; i < strs.length; i++){

            while(!strs[i].startsWith(ret)){
                ret = strs[i].substring(0,ret.length()-1);
                if(ret.length() == 0){
                    return "";
                }
            }
        }
        return ret;
    }
}
